package test;
import lib.db_properties_path.*;
import java.sql.*;
import java.util.*;
import lib.dbTool.*;


public class CONNECTRELATION extends DBconnection2 {
public CONNECTRELATION(SetPath set){
super(set);
}
public CONNECTRELATION(){
super(new DefaultSetPath());
}
/** Auto Increasment */
/** Primary Key */
/** int identity ; java.lang.Integer */private int idrelation;
/** nvarchar ; java.lang.String */private String namerelation;
/** nvarchar ; java.lang.String */private String telrelation;
/** nvarchar ; java.lang.String */private String relrelation;
/** int ; java.lang.Integer */private int idoldman;
/** nvarchar ; java.lang.String */private String firstconnect;
public int getIdrelation(){
return  idrelation;
}
public void setIdrelation(int idrelation){
this.idrelation= idrelation;
}

public String getNamerelation(){
return  namerelation;
}
public void setNamerelation(String namerelation){
this.namerelation= namerelation;
}

public String getTelrelation(){
return  telrelation;
}
public void setTelrelation(String telrelation){
this.telrelation= telrelation;
}

public String getRelrelation(){
return  relrelation;
}
public void setRelrelation(String relrelation){
this.relrelation= relrelation;
}

public int getIdoldman(){
return  idoldman;
}
public void setIdoldman(int idoldman){
this.idoldman= idoldman;
}

public String getFirstconnect(){
return  firstconnect;
}
public void setFirstconnect(String firstconnect){
this.firstconnect= firstconnect;
}

public interface fn{
String TABLE_NAME = "CONNECTRELATION";
String PK = "idrelation";
String idrelation="idrelation";
String namerelation="namerelation";
String telrelation="telrelation";
String relrelation="relrelation";
String idoldman="idoldman";
String firstconnect="firstconnect";
}
public String sql(String SQL){
return Utility.getSQL組合字(SQL, CONNECTRELATION.fn.class);
}
public int clear() {
String SQL = "delete from CONNECTRELATION";
Object parameter[] = {};
return super.excuteUpdate(SQL, parameter);
}

public int delete(int idrelation) {
String SQL = "delete from CONNECTRELATION where idrelation=?";
Object parameter[] = {idrelation};
return super.excuteUpdate(SQL, parameter);
}

public int update(String namerelation,String telrelation,String relrelation,int idoldman,String firstconnect, int idrelation){
String SQL = "update CONNECTRELATION set namerelation=?,telrelation=?,relrelation=?,idoldman=?,firstconnect=? where idrelation=?";
Object parameter[] = {namerelation,telrelation,relrelation,idoldman,firstconnect,idrelation};
return super.excuteUpdate(SQL,parameter);
}

public int insert(String namerelation,String telrelation,String relrelation,int idoldman,String firstconnect){
String SQL = "insert into CONNECTRELATION(namerelation,telrelation,relrelation,idoldman,firstconnect) values(?,?,?,?,?)";
Object parameter[] = { namerelation,telrelation,relrelation,idoldman,firstconnect};
return super.excuteUpdate(SQL ,parameter);
}

public String[][] select() {
String SQL = "select * from CONNECTRELATION";
Object parameter[] = {};
return super.select(SQL, parameter);
}

public CONNECTRELATION[] select_Object() {
String SQL = "select * from CONNECTRELATION";
Object parameter[] = {};
String data[][] = super.select(SQL, parameter);CONNECTRELATION obj[] = toObject(data);return obj;}

public String[][] select( int idrelation) {
String SQL = "select * from CONNECTRELATION where idrelation=?";
Object parameter[] = {idrelation};
return super.select(SQL, parameter);}

public CONNECTRELATION[] select_Object( int idrelation) {
String data[][] = this.select(idrelation);CONNECTRELATION obj[] = toObject(data);return obj;}

public int selectCount() {
String SQL = "select count(idrelation) from CONNECTRELATION";
Object parameter[] = {};
String d[][] = super.select(SQL, parameter);
return Integer.parseInt(d[0][0]);}

public String[][] selectPage(int pageSize, int pageIndex, int rowCount) {
int desc = PaggingSQL.ASC;PaggingSQL ps = new lib.dbTool.MsSQL2012();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;String SQL = ps.getSelectPage(pageSize, pageIndex, TABLE_NAME, PK, desc, rowCount);Object parameter[] = {};
return super.select(SQL, parameter);
}
public String[][] selectPageOrderBy(int pageSize, int pageIndex, String sortName, int desc, int rowCount) {
PaggingSQL ps = new lib.dbTool.MsSQL2012();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;String SQL = ps.getSelectPageOrderBy(pageSize, pageIndex, TABLE_NAME, PK, sortName, desc, rowCount);Object parameter[] = {};
return super.select(SQL, parameter);
}
 /**
 * 關鍵字 where 不用寫
 * @param pageSize
 * @param pageIndex
 * @param sortName
 * @param desc
 * @param rowCount
 * @param whereCondition = 【pk>0】, 關鍵字 where 不用寫
 * @return
 */
public String[][] selectPageOrderBy(int pageSize, int pageIndex, String sortName, int desc, int rowCount, String whereCondition) {
PaggingSQL ps = new lib.dbTool.MsSQL2012();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;
//範例,關鍵字 where 不用寫, ex:【pk>0】
String SQL = ps.getSelectPageOrderBy(pageSize, pageIndex, TABLE_NAME, PK, sortName, desc, rowCount, whereCondition);Object parameter[] = {};
return super.select(SQL, parameter);
}
public CONNECTRELATION[] selectPage_Object(int pageSize, int pageIndex, int rowCount) {
	String data[][] = this.selectPage(pageSize, pageIndex, rowCount);
	CONNECTRELATION obj[] = toObject(data);
	return obj;
}
 /**
 * 分組統計筆數
 * @param fk_List
 * @return
 */
public Map<Integer, Integer> getGroupCount(String fkName, LinkedList<Integer> fk_List){String q = "";
Object parameter[] = new Object[fk_List.size()];
int i=0;
for (Integer no : fk_List) {
q += "?,";
parameter[i++] = no;
}
if (q.length() > 0){
q = q.substring(0, q.length()-1);
}
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();String SQL = "";SQL += "SELECT "+ fkName +", count("+ fkName +") ";SQL += "FROM "+ fn.TABLE_NAME +" where "+fkName+" in (" + q + ")";SQL += "group by "+ fkName +";";String data[][] = super.select(SQL, parameter);for (int j = 0; j < data.length; j++) {int key = Integer.parseInt(data[j][0]);int count = Integer.parseInt(data[j][1]);map.put(key, count);}return map;} /**
 * Where PK in(?,?,?....)
 * @param idList
 * @return
 */
public Map<Integer, CONNECTRELATION> selectMap(LinkedList<Integer> idList){
String q = "";
Object parameter[] = new Object[idList.size()];
int i=0;
for (Integer no : idList) {
q += "?,";
parameter[i++] = no;
}
if (q.length() > 0){
q = q.substring(0, q.length()-1);
}
HashMap<Integer, CONNECTRELATION> map = new HashMap<Integer, CONNECTRELATION>();

String SQL = "select * from CONNECTRELATION where idrelation in ("+ q +")";
String data[][] = super.select(SQL, parameter);
CONNECTRELATION[] obj = this.toObject(data);
for (CONNECTRELATION o : obj) {
map.put(new Integer(o.idrelation) , o);
}
return map;
}
public CONNECTRELATION[] toObject(String data[][]){
CONNECTRELATION[] obj = new CONNECTRELATION[data.length];
for (int i = 0; i < obj.length; i++) {
obj[i] = new CONNECTRELATION(super.getSetting());obj[i].idrelation=Integer.parseInt(data[i][0]);
obj[i].namerelation=data[i][1];
obj[i].telrelation=data[i][2];
obj[i].relrelation=data[i][3];
obj[i].idoldman=Integer.parseInt(data[i][4]);
obj[i].firstconnect=data[i][5];
}
return obj;}
}